#ifndef StackH
#define StackH


#include "List.h"


namespace AlgolistManual
{


template<class T> class Stack {
 private :
  List<T> *s;
 public :
  Stack (void);
  ~Stack (void);
  void push (T v);
  T pop (void);
  bool empty (void);
  int size (void);
  T top (void);
  T nextToTop (void);
  T bottom (void);
};


template<class T>
inline Stack<T>::Stack (void) :
  s (new List<T>)
{
}

template<class T>
inline Stack<T>::~Stack (void)
{
  delete s;
}

template<class T>
inline void Stack<T>::push(T v)
{
  s->prepend(v);
}

template<class T>
inline T Stack<T>::pop(void)
{
  s->first();
  return s->remove();
}

template<class T>
inline bool Stack<T>::empty(void)
{
  return (s->length() == 0);
}

template<class T>
inline int Stack<T>::size (void)
{
  return s->length(); 
}

template<class T>
inline T Stack<T>::top (void)
{
  return s->first();
}

template<class T>
inline T Stack<T>::nextToTop (void)
{
  s->first();
  return s->next();
}

template<class T>
inline T Stack<T>::bottom (void)
{
  return s->last();
}


} // namespace AlgolistManual


#endif // StackH